﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Module.Core.EntitiesInfo;
using Module.Common.Models;

namespace Module.Core.DAO
{
	public class MemberDAO
	{
		#region Fields

		protected string connectionStringName;

		#endregion

	
       #region Methods

		/// <summary>
		/// Saves a record to the Member table.
		/// </summary>
		public virtual int Insert(MemberInfo memberInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@FullName", memberInfo.FullName),
				new SqlParameter("@Address", memberInfo.Address),
				new SqlParameter("@Email", memberInfo.Email),
				new SqlParameter("@Pass", memberInfo.Pass),
				new SqlParameter("@PhoneNumber", memberInfo.PhoneNumber),
				new SqlParameter("@Status", memberInfo.Status),
				new SqlParameter("@CodeMember", memberInfo.CodeMember),
				new SqlParameter("@CodeMemberParent", memberInfo.CodeMemberParent),
				new SqlParameter("@CodePosition", memberInfo.CodePosition),
				new SqlParameter("@CreatedOn", memberInfo.CreatedOn),
				new SqlParameter("@Leve", memberInfo.Leve),
				new SqlParameter("@Checktype", memberInfo.Checktype),
				new SqlParameter("@LeftRight", memberInfo.LeftRight),
				new SqlParameter("@PriceMount", memberInfo.PriceMount),
				new SqlParameter("@DateBirth", memberInfo.DateBirth),
                new SqlParameter("@UserName", memberInfo.UserName),
                new SqlParameter("@IsActive", memberInfo.IsActive),      
                new SqlParameter("@NumberAcount", memberInfo.NumberAcount),
                new SqlParameter("@NameBank", memberInfo.NameBank),
                new SqlParameter("@CMTND", memberInfo.CMTND),
               new SqlParameter("@Promotional", memberInfo.Promotional)
			};

			return (int) SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "Member_Insert", parameters);
		}

		/// <summary>
		/// Updates a record in the Member table.
		/// </summary>
		public virtual void Update(MemberInfo memberInfo)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IdMember", memberInfo.IdMember),
				new SqlParameter("@FullName", memberInfo.FullName),
				new SqlParameter("@Address", memberInfo.Address),
				new SqlParameter("@Email", memberInfo.Email),
			    new SqlParameter("@PhoneNumber", memberInfo.PhoneNumber),								
				new SqlParameter("@CodeMemberParent", memberInfo.CodeMemberParent),
				new SqlParameter("@CodePosition", memberInfo.CodePosition),
				new SqlParameter("@CreatedOn", memberInfo.CreatedOn),
				new SqlParameter("@Leve", memberInfo.Leve),
				new SqlParameter("@Checktype", memberInfo.Checktype),
				new SqlParameter("@LeftRight", memberInfo.LeftRight),
				new SqlParameter("@PriceMount", memberInfo.PriceMount),
				new SqlParameter("@DateBirth", memberInfo.DateBirth),
                new SqlParameter("@UserName", memberInfo.UserName),
                new SqlParameter("@NumberAcount", memberInfo.NumberAcount),
                new SqlParameter("@NameBank", memberInfo.NameBank),
                new SqlParameter("@CMTND", memberInfo.CMTND)
             
              
			};

			SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_Update", parameters);
		}

        public virtual void UpdateSumNoteTree(string codeMember, int sumNoteTree)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CodeMember",codeMember),
                new SqlParameter("@SumNoteTree",sumNoteTree)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_SumNoteTree", parameters);
        }
        public virtual void UpdateLeftRight(string codeMember, string  leftRight)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CodeMember",codeMember),
                new SqlParameter("@LeftRight",leftRight)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_Update_LeftRight", parameters);
        }
        public virtual void UpdateCodeMemberParent(string codeMember, int idMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CodeMember",codeMember),
                new SqlParameter("@IdMember",idMember)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateCodeMemberParent", parameters);
        }
        public virtual void ChangesPass(string  email,string pass)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Email",email),
				new SqlParameter("@NewPass",pass),
				
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_ChangesPass", parameters);
        }

		/// <summary>
		/// Deletes a record from the Member table by its primary key.
		/// </summary>
		public virtual void Delete(int idMember)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IdMember", idMember)
			};

			SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_Delete", parameters);
		}

		
        public virtual MemberInfo Select(string param,int type)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@param", param),
                new SqlParameter("@Status", type),
			};
            try
            {
                using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters))
                {
                    if (dataReader.Read())
                    {
                        return MakeMemberInfo(dataReader);
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            catch (Exception)
            {                                
            }
            return null;
		}

       

        public CHRTList<MemberInfo> SelectList(string param, int type)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@param", param),
                                                new SqlParameter("@Status", type),
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters))
            {
                CHRTList<MemberInfo> memberInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo memberInfo = MakeMemberInfo(dataReader);
                    memberInfoList.Add(memberInfo);
                }

                return memberInfoList;
            }
        }
 
        //hiện thị thông tin cá nhân
        public virtual MemberInfo SelectProFile(string email)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Email",email)
               
			};

            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectProFile", parameters))
            {
                if (dataReader.Read())
                {
                    return MakeMemberInfo(dataReader);
                }
                else
                {
                    return null;
                }
            }
         }

        
        //sửa thông tin cá nhân
        public virtual void UpdateProfile(MemberInfo memberInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				
				new SqlParameter("@FullName", memberInfo.FullName),
				new SqlParameter("@Address", memberInfo.Address),
				new SqlParameter("@Email", memberInfo.Email),
			    new SqlParameter("@PhoneNumber", memberInfo.PhoneNumber),
				new SqlParameter("@NumberAcount", memberInfo.NumberAcount),
                new SqlParameter("@NameBank", memberInfo.NameBank),
                new SqlParameter("@CMTND", memberInfo.CMTND)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateProfile", parameters);
        }
        public virtual DataTable Bonus(string codeMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CodeMember", codeMember),
               
                               
			};
            using (DataTable dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_Bonus", parameters))
            {
                return dt;
            }
        }
        //Hiện thị top 10 thành viên đăng ký mới nhất
        public virtual DataTable DisplayTop20(int status)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Status", status),
               
                               
			};
            using (DataTable dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_SelectTop20", parameters))
            {
                return dt;
            }
        }
        //hiện thị thông tin thành viên khi đăng nhập vào hệ thống
        public virtual DataTable DisplayMember(string email)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Email", email),	
                               
			};
            using (DataTable dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Select_Member", parameters))
            {
                return dt;
            }
        }
        //update CheckType của thành viên
       
        public virtual void UpdateCheckType(int idMember, int checktype)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@IdMember", idMember),
                new SqlParameter("@Checktype", checktype),
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateChecktype", parameters);
        }

		/// <summary>
		/// Selects all records from the Member table.
		/// </summary>
       
		public CHRTList<MemberInfo> SelectAll(int status)
		{
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@Status",status)
        };
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectAll",parameters))
			{
				CHRTList<MemberInfo> memberInfoList = new CHRTList<MemberInfo>();
				while (dataReader.Read())
				{
					MemberInfo memberInfo = MakeMemberInfo(dataReader);
					memberInfoList.Add(memberInfo);
				}

				return memberInfoList;
			}
		}
 
        public CHRTList<MemberInfo> SearchAll(string email, int status, int from, int to, int checkType, DateTime createdOnFrom, DateTime createdOnTo)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@Email",email),
                                              new SqlParameter("@Status",status),
                                              new SqlParameter("@CheckType",checkType),
                                              new SqlParameter("@CreatedOnFrom",createdOnFrom),
                                              new SqlParameter("@CreatedOnTo ",createdOnTo),
                                              new SqlParameter("@From",from),
                                              new SqlParameter("@To",to)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SearchAll", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }

        public CHRTList<MemberInfo> GetParentLeveMember(int type, string codeMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@CodeMember",codeMember),
                                              new SqlParameter("@Type",type)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParentLeve", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }

        public CHRTList<MemberInfo> GetParenMatrix(string codeMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                                                                            
                                              new SqlParameter("@CodeMember",codeMember)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectMatrix", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }

        public CHRTList<MemberInfo> GetParentMember(int type, int idMember,int leve)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                              
                                              new SqlParameter("@Type",type),
                                              new SqlParameter("@IdMember",idMember),
                                               new SqlParameter("@leve",leve)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParent", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }

        public CHRTList<MemberInfo> GetParentLeveMemberFull(string idMember, int checkType)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                              
                                            new SqlParameter("@IdMember",idMember),
                                            new SqlParameter("@CheckType",checkType)
                                            
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParentLeveFull", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }
        public CHRTList<MemberInfo> GetParentLeveMemberFull_Search(string codeMember ,string keysearch)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                              
                                            new SqlParameter("@CodeMember",codeMember),
                                            new SqlParameter("@CodeMember_KeyWord" ,keysearch)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParentLeveFullSearch", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }
        public DataTable Get10Row(int BeginRow , int EndRow, int IsTotalRow)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@BeginRow", BeginRow),
                new SqlParameter("@EndRow", EndRow),
                new SqlParameter("@IsTotalRow", IsTotalRow)
                

			};
            DataTable dt = new DataTable();
            dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_SearchParentLeveFull", parameters);

            if (dt != null && dt.Rows.Count > 0)
                return dt;
            return null;
        }
        public CHRTList<MemberInfo> GetParentLeveMemberFullTop(string codeMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                              
                                            new SqlParameter("@CodeMember",codeMember)

        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParentTop", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }
        public CHRTList<MemberInfo> GetParentLeveMemberFullEnd(string codeMember)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {                                              
                                            new SqlParameter("@CodeMember",codeMember)
        };
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "Member_SelectParentend", parameters))
            {
                CHRTList<MemberInfo> productInfoList = new CHRTList<MemberInfo>();
                while (dataReader.Read())
                {
                    MemberInfo productInfo = MakeMemberInfo(dataReader);
                    productInfoList.Add(productInfo);
                }

                return productInfoList;
            }
        }
        public int GetCount(string fullname, int status)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                            {
                                                new SqlParameter("@Email", fullname),
                                                new SqlParameter("@Status", status),
                                              
                                            };
            return
                (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "Member_GetCount", parameters);

        }
        public int GetCountLeftRight(string codeMember, string leftRight)
        {
            int cout = 0;
            SqlParameter[] parameters = new SqlParameter[]
                                            {
                                                new SqlParameter("@CodeMember", codeMember),
                                                new SqlParameter("@LeftRight", leftRight),
                                              
                                            };
            cout = (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "Member_CountNoteRoot", parameters);
            
            return cout;                

        }

        /// <summary>
        /// Lấy tổng số Gold trong tài khoản 
        /// </summary>
        /// <param name="email"></param>        
        /// <returns></returns>
        public int GetGold(string email)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                            {
                                                new SqlParameter("@email", email)
                                              
                                            };
            return
                (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "Member_GetGold", parameters);

        }
        /// <summary>
        /// Cộng số tiền người nhận và trừ số tiền người chuyển khoản
        /// </summary>
        /// <param name="type">type=1</param>
        /// <param name="emailChuyen">Email người chuyển tiền</param>
        /// <param name="emailNhan">Email người nhận tiền</param>
        /// <param name="sotienchuyen">Số tiền cần chuyển</param>
        ///

     //Chuyển gold qua tài khoản bằng email
        public virtual void UpdateGold(int type, string codeMember_from, string codeMember_To, int sotienchuyen)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@type", type),
				new SqlParameter("@CodeMember_From", codeMember_from),
				new SqlParameter("@CodeMember_To", codeMember_To),
				new SqlParameter("@Sotienchuyen", sotienchuyen)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateGold", parameters);
        }
        //Cộng tiền khuyến mãi cho thành viên đăng ký và giới thiều
        public virtual void Member_UpdatePromotional(int type, string codeMember, double sotienchuyen)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@type", type),
				new SqlParameter("@CodeMember", codeMember),
				new SqlParameter("@Promotional", sotienchuyen)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdatePromotional", parameters);
        }

        //Chuyển gold qua tài khoản bằng ATM

        public virtual void UpdateGoldATM(int type, string codeMemberFrom, string sotaikhoan, int sotienchuyen)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@type", type),
				new SqlParameter("@CodeMemberFrom", codeMemberFrom),
				new SqlParameter("@NumberAcount", sotaikhoan),
				new SqlParameter("@Sotienchuyen", sotienchuyen)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateGoldATM", parameters);
        }
        

        public virtual void UpdateNapGold(int idMember,int type, string email, float sotienchuyen,int param)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
                new SqlParameter("@IdMember", idMember),
				new SqlParameter("@type", type),
				new SqlParameter("@Email", email),
			    new SqlParameter("@Sotienchuyen", sotienchuyen),
                new SqlParameter("@Param", param)
              
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateNapGold", parameters);
        }
        //nạp gold vào tài khoản Member
        public virtual void UpdateNapGoldMember(int type, string email, float sotienchuyen)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
                new SqlParameter("@type", type),
				new SqlParameter("@Email", email),
			    new SqlParameter("@Sotienchuyen", sotienchuyen)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateNapGoldMember", parameters);
        }


        //Update khi quên mật khẩu
        public virtual void MemberUpdatePassword(string email, string password)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
               
				new SqlParameter("@Email", email),
			    new SqlParameter("@Password", password)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdatePassword", parameters);
        }
        public virtual void MemberUpdateBonus(int checktype, string codeMember, float goldBonus)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
               
				new SqlParameter("@Checktype", checktype),
			    new SqlParameter("@CodeMember", codeMember),
                new SqlParameter("@GoldBonus", goldBonus)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "Member_UpdateGoldBonus", parameters);
        }
        
        
        /// <summary>
        /// check email đã tồn tại hay chưa
        /// <summary>

        public bool  CheckEmail(string email,int param)
        {
            DataTable dt=new DataTable();
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@param", email),
                new SqlParameter("@Status", param)
            };
            dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters);
            if (dt != null && dt.Rows.Count > 0)
                return true;
            return false;
        }


        /// <summary>
        /// check PhoneNumber đã tồn tại hay chưa
        /// <summary>

        public bool CheckPhoneNumber(string phoneNumber,int param)
        {
            DataTable dt = new DataTable();
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@param", phoneNumber),
                new SqlParameter("@Status", param)
            };
            dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters);
            if (dt != null && dt.Rows.Count > 0)
                return true;
            return false;
        }

        /// <summary>
        /// check PhoneNumber đã tồn tại hay chưa
        /// <summary>

        public bool CheckCMTND(string cmtnd, int param)
        {
            DataTable dt = new DataTable();
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@param", cmtnd),
                new SqlParameter("@Status", param)
            };
            dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters);
            if (dt != null && dt.Rows.Count > 0)
                return true;
            return false;
        }

        /// <summary>
        /// Thống kê theo level
        /// <summary>


        public DataTable MemberCountLevel()
        {
            SqlParameter[] parameters = new SqlParameter[] {};
            using (DataTable dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_CountLevel", parameters))
            {
                return dt;
            }

        }

        public int GetTotalMember()
        {
            SqlParameter[] parameters = new SqlParameter[] { };
                                               
                                              
                                            
            return
                (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "Member_CountTotal", parameters);

        }

        //Khi nhập mã thành viên thì hiện thị ra tên thành viên đó
        public virtual DataTable GetRecords(string codeMember, int param)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@param", codeMember),	
                	new SqlParameter("@Status", param)
                               
			};
            using (DataTable dt = SqlClientUtility.ExecuteDataTable(connectionStringName, CommandType.StoredProcedure, "Member_Select", parameters))
            {
                return dt;
            }
        }
		/// <summary>
		/// Creates a new instance of the Member class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected virtual MemberInfo MakeMemberInfo(SqlDataReader dataReader)
		{
			MemberInfo memberInfo = new MemberInfo();
			memberInfo.IdMember = SqlClientUtility.GetInt32(dataReader,DbConstants.MEMBER.IDMEMBER, 0);
			memberInfo.FullName = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.FULLNAME, String.Empty);
			memberInfo.Address = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.ADDRESS, String.Empty);
			memberInfo.Email = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.EMAIL, String.Empty);
			memberInfo.Pass = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.PASS, String.Empty);
			memberInfo.PhoneNumber = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.PHONENUMBER, String.Empty);
			memberInfo.Status = SqlClientUtility.GetInt32(dataReader,DbConstants.MEMBER.STATUS, 0);
			memberInfo.CodeMember = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.CODEMEMBER, String.Empty);
			memberInfo.CodeMemberParent = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.CODEMEMBERPARENT, String.Empty);
			memberInfo.CodePosition = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.CODEPOSITION, String.Empty);
			memberInfo.CreatedOn = SqlClientUtility.GetDateTime(dataReader,DbConstants.MEMBER.CREATEDON, DateTime.Now);
			memberInfo.Leve = SqlClientUtility.GetInt32(dataReader,DbConstants.MEMBER.LEVE, 0);
			memberInfo.Checktype = SqlClientUtility.GetInt32(dataReader,DbConstants.MEMBER.CHECKTYPE, 0);
			memberInfo.LeftRight = SqlClientUtility.GetString(dataReader,DbConstants.MEMBER.LEFTRIGHT, String.Empty);
			memberInfo.PriceMount = SqlClientUtility.GetInt32(dataReader,DbConstants.MEMBER.PRICEMOUNT, 0);
			memberInfo.DateBirth = SqlClientUtility.GetDateTime(dataReader,DbConstants.MEMBER.DATEBIRTH, DateTime.Now);
		    memberInfo.NumberAcount = SqlClientUtility.GetString(dataReader, DbConstants.MEMBER.NUMBERACOUNT, String.Empty);
            memberInfo.NameBank = SqlClientUtility.GetString(dataReader, DbConstants.MEMBER.NAMEBANK, String.Empty);
            memberInfo.UserName = SqlClientUtility.GetString(dataReader, DbConstants.MEMBER.USERNAME, String.Empty);           
            memberInfo.IsActive = SqlClientUtility.GetBoolean(dataReader, DbConstants.MEMBER.ISACTIVE, false);
            memberInfo.GoldBonus = SqlClientUtility.GetFloat(dataReader, DbConstants.MEMBER.GOLDBONUS, 0);
            memberInfo.CMTND = SqlClientUtility.GetString(dataReader, DbConstants.MEMBER.CMTND, String.Empty);
            memberInfo.Promotional = SqlClientUtility.GetFloat(dataReader, DbConstants.MEMBER.PROMOTIONAL, 0);


			return memberInfo;
		}

       

		#endregion
	}
}
